<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/18
 * Time: 22:00
 */

namespace App\Admin\Controllers;

use App\Admin\Traits\UserTrait;
use App\Helper;
use App\Models\GroupMessage;
use Encore\Admin\Actions\Action;
use Encore\Admin\Admin;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class MessageController extends AdminController
{
    use UserTrait;

    public function index(Content $content)
    {
        $uid = $this->getUserId();

        return $content
            ->title("微信群消息列表")
            ->body($this->grid());
    }

    public function grid()
    {
        $model = new GroupMessage();
        $grid = new Grid($model);
        $grid->disableCreateButton();
        $grid->disableExport();
        $grid->filter(function ($filter) {

            // 设置created_at字段的范围查询
            $filter->between('created_at', 'Created Time')->datetime();
        });
        $grid->actions(function(Action $row) {
            $row->text("操作");
        });
        Helper::gridLoadModel($grid, $model);
        return $grid;
    }
}